#include <stdint.h>
#include "gd32f30x.h"
#include "battery_drv.h"
#include "lcd_drv.h"
#include "systick.h"

extern PictureDesc_t g_batPercentPicsDesc[];

void BatteryLcdDisplay(void)
{
	static uint64_t lastSysTime = 0;
	static bool batFlag = false;
	BatteryLevel_t batLevel = GetBatteryLevel();
	if (batLevel > BATTERY_LEVEL_GRID_4)
	{
		return;
	}
	if (GetSysRunTime() - lastSysTime >= 500)
	{
		lastSysTime = GetSysRunTime();
		if (GetBatteryState() == BATTERY_IS_CHARGING)
		{
			batFlag = !batFlag;
		}
		else
		{
			 batFlag = false;
		}
		
		if (batFlag && (batLevel < BATTERY_LEVEL_GRID_4))
		{
			batLevel++;
		}
		LcdDrawPicture(210, 0, WHITE, BLACK, &g_batPercentPicsDesc[batLevel]);
	}
}
